Skip to main content

Initialize your Service

In this guide, you will create a service called dummy-controller in C, interface it with the official imaging and actuator services, upload it to the Rover and execute it.

Elias Groot

Elias Groot

Software Lead, Course Organizer

Before you can get started writing any code, make sure to properly initialize your workspace on your own device (your laptop).

  1. Create a folder called dummy-controller and enter it
mkdir dummy-controller && cd dummy-controller
  1. Initialize the required folder structure using roverctl and enter the required information
roverctl service init

(Alternatively, you can clone our Go service template)

  1. Upload the initial version of your service to the Rover (if it is powered on)
roverctl service sync
  1. (Optional) open the directory in VS Code and hit ctrl+shift+p. Then select "Dev Containers: Rebuild and Reopen in Container". The build process might take a while the first time. Once built, open a terminal in VS Code and try to build the service

VS Code open in Devcontainer

make build

Service Entrypoint

Take a look at the main() function in src/main.c. You will see a reference to run(). The defined user_program() function is the entrypoint of your service, it will be executed once the roverlib processed your service data. This is where your code should live.

The provided user_program() function already illustrates how to use the most important methods that the roverlib-c shared object provides. Try and see if you can follow what the example code does and why you might need this.

After that, clear the contents of the user_program() function. We will start from scratch, so your source code should look like this:

src/main.c
#include <roverlib.h>
#include <sys/time.h>
#include <unistd.h>

long long current_time_millis() {
struct timeval tv;
gettimeofday(&tv, NULL);
return (long long)(tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
}

// The main user space program
// this program has all you need from roverlib: service identity, reading, writing and configuration
int user_program(Service service, Service_configuration *configuration) {

}

// This is just a wrapper to run the user program
// it is not recommended to put any other logic here
int main() {
return run(user_program);
}